<template>
<div class="save-wrapper ui container" v-if="show">
  <div class="ui very relaxed  grid">
    <div class="sixteen wide column">

      <form action="" class="ui form" @submit.prevent="submit_confirm">
        <div class="ui header">{{titleType}}属性</div>

        <div class="fluid field">
          <label for="">标题</label>
          <input type="text" v-model="vo.title" name="title" placeholder="请输入标题">
        </div>

        <div class="fluid field">
          <label for="">英文名</label>
          <input type="text" v-model="vo.name" name="name" placeholder="请输入英文名">
        </div>
        <div class="fluid field">
          <label for="">备注</label>
          <textarea  v-model="vo.desc" name="desc" placeholder="请输入备注"></textarea>
        </div>

        <div class="fluid field">
          <label for="">类型</label>
          <!-- <div class="ui search selection dropdown">
            <input type="hidden" name='type' @change="valChane($el)">
            <div class="default text">请选择</div>
            <i class="dropdown icon"></i>
            <div class="ui menu">
              <div class="item" v-for=" (item,key) in typeData" :data-value="key">{{item}}</div>
            </div>
          </div> -->
          <fselect fname="type" @selectValsChange='valChane' :val="ftype" :data="typeData" v-if="typeData" placeholder="请选择类型"></fselect>

        </div>

        <div class="fluid field" v-show="is_enum">
          <label for="">枚举值</label>
          <input type="text" v-model="vo.enum_val" name="enum_val" placeholder="请输入枚举值">
        </div>

        <div class="fluid field" v-show="is_custom">
          <label for="">自定义字段组件名</label>
          <input type="text" v-model="vo.custom" name="custom" placeholder="请输入自定义字段组件名">
        </div>

        <myenum :param="{}" v-if="is_pic&&enumField_pic_dir.fval!==undefined" :field="enumField_pic_dir" @setVo='setEnum' ></myenum>
        <myenum :param="{}" v-if="is_pic&&enumField_pic_type.fval!==undefined" :field="enumField_pic_type" @setVo='setEnum' ></myenum>
        <myenum :param="{}" v-if="is_pic&&enumField_pic_full_url.fval!==undefined" :field="enumField_pic_full_url" @setVo='setEnum' ></myenum>

        <myenum :param="{}" v-if="is_city&&enumField_city_type.fval!==undefined" :field="enumField_city_type" @setVo='setEnum' ></myenum>

        <myenum :param="{}" v-if="is_city&&is_city_mul==1&&enumField_city_need_all.fval!==undefined" :field="enumField_city_need_all" @setVo='setEnum' ></myenum>

        <myenum :param="{}" v-if="is_zip&&enumField_inline.fval!==undefined" :field="enumField_inline" @setVo='setEnum' ></myenum>
        <myenum :param="{}" v-if="is_enum&&enumField_enum_type.fval!==undefined" :field="enumField_enum_type" @setVo='setEnum' ></myenum>
        <!--<myenum :param="{}" v-if="enumField_is_judge.fval!==undefined" :field="enumField_is_judge" @setVo='setEnum' ></myenum>-->
        <!--<myenum :param="{}" v-if="enumField_is_field_type_ctl.fval!==undefined" :field="enumField_is_field_type_ctl" @setVo='setEnum' ></myenum>-->
        <myenum :param="{}" v-if="is_num&&enumField_num_formoney.fval!==undefined" :field="enumField_num_formoney" @setVo='setEnum' ></myenum>
        <myenum :param="{}" v-if="is_zip&&enumField_showZipTitle.fval!==undefined" :field="enumField_showZipTitle" @setVo='setEnum' ></myenum>

        <div class="fluid field">
          <label for="">默认值</label>
          <input type="text" v-model="vo.def" name="def" placeholder="请输入默认值">
        </div>

        <!--<select_iv></select_iv>-->

        <p class="submitRow">
            <button type="submit" :class="{loading:loadingBtn}" class="ui button">提 交</button>
        </p>
      </form>


    </div>
  </div>
</div>
</template>
<script>
import tool from 'src/util/tool';
import util from '_util/index';
import logic from '_logic';
import fselect from 'components/form/select'
//import select_iv from 'components/form/select_iv'
import myenum from 'components/field/enum';

export default {
  data() {
    return {
      result: '',
      type: 'add',
        loadingBtn: false,
      model: {},
      enumField_pic_dir:{
        name:'pic_dir',
        title:'图片目录',
          enum_type:1,
        enum_val:[
          'hotel','product'
        ]
      },
      enumField_city_type:{
        name:'city_type',
        title:'城市类型',
        enum_type:1,
        enum_val:[
          '单选','多选'
        ]
      },
      enumField_pic_type:{
        name:'pic_type',
        title:'图片类型',
        enum_type:1,
        enum_val:[
          '单图','多图'
        ]
      },
      enumField_pic_full_url:{
        name:'pic_full_url',
        title:'是否需要完整地址',
        enum_type:1,
        enum_val:[
            '否','是'
        ]
      },
      enumField_city_need_all:{
        name:'city_need_all',
        title:'城市里是否显示"全部"选项',
        enum_type:1,
        enum_val:[
          '否','是'
        ]
      },
      enumField_is_judge:{
        name:'is_judge',
        title:'是否是Judge字段',
        enum_type:1,
        enum_val:[
          '否','是'
        ]
      },
      enumField_is_field_type_ctl:{
        name:'is_field_type_ctl',
        title:'是否是字段类型控制字段',
        enum_type:1,
        enum_val:[
          '否','是'
        ]
      },
      enumField_inline:{
        name:'inline',
        title:'是否单行展示',
        enum_type:1,
        enum_val:[
          '否','是'
        ]
      },
      enumField_enum_type:{
        name:'enum_type',
        title:'枚举（单选）类型',
        enum_type:1,
        enum_val:[
          '下拉菜单','radio'
        ]
      },
      enumField_num_formoney:{
        name:'num_formoney',
        title:'价格字段',
        enum_type:1,
        enum_val:[
          '否','是'
        ]
      },
      enumField_showZipTitle:{
        name:'showZipTitle',
        title:'是否显示组名',
        enum_type:1,
        enum_val:[
          '否','是'
        ]
      },
      pidinfo: {
        title: '父级',
        name: 'pid'
      },
      typeData: null,
        is_city_mul: false,
      mdata: {},
      vo: null,
      tabs: [],
      fields: {},
      result_type: 'rs_error',
      curIndex: '1',
      ftype: '1',
      show: true
    }
  },
  watch: {
    'vo.city_type': function(val, old) {
        this.is_city_mul = val;
        if(val==0)
            this.vo.city_need_all=0;
    },
    ftype: function(val, old) {
      if (val == 4) {
        this.vo.def = 0

      }
    }
  },
  methods: {
    setEnum(name, val) {
        this.$set(this.vo, name, val);

//      this.vo[name]= val;
    },
    valChane(type) {
      this.ftype = type
      this.vo.type = type

    },
    getType() {
       util.getHardCode(this,'attr_type_new',(rs)=> {
         this.typeData = rs;
       })
    },
    submit_confirm() {
      util.showConfirm(this, () => {
        this.onSubmit()
      },{content:'确认提交吗？'});
    },
    onSubmit() {
      let op = this.$store.state.global.op || 'insert';
      let url = tool.getApi(this,'Attr', op);
        logic.edit.setSaveLoading(this);

      util.http.SR(this, url, this.vo, '操作成功',()=>{
          this.loadingBtn = false;
        let eventVue = util.store.get(this,'eventVue');
        eventVue.$emit('afterAdd')
      });

    }
  },
  computed: {
    titleType() {
      return logic.edit.get_titleType(this);
    },
    ctl() {
      return this.$route.query.ctl;
    },
//    vo() {
//      return this.$store.state.global.editVo || {};
//    },
    is_enum() {
      return [3,18,19].contains(this.ftype);
    },
    is_custom() {
      return this.ftype == 13;
    },
    is_pic() {
      return this.ftype == 7;
    },
    is_city() {
      return this.ftype == 12;
    },
    is_num() {
      return this.ftype == 4;
    },
    is_zip() {
      return this.ftype == 11;
    },
    is_enum() {
      return this.ftype == 3;
    },
  },
  components: {
    fselect,
    myenum
  },
  mounted() {

  },
  props: ['leftMenu', 'user', 'path', 'isAdd'],
  created() {
    this.vo=util.store.get(this, 'editVo')

    this.getType()
    this.ftype=this.vo.type||1
    this.enumField_pic_dir.fval=this.vo['pic_dir']||0
    this.enumField_pic_type.fval=this.vo['pic_type']||0
    this.enumField_city_type.fval=this.vo['city_type']||0
    this.enumField_inline.fval=this.vo['inline']||0
    this.enumField_is_judge.fval=this.vo['is_judge']||0
    this.enumField_num_formoney.fval=this.vo['num_formoney']||0
    this.enumField_showZipTitle.fval=this.vo['showZipTitle']||1
    this.enumField_city_need_all.fval = this.vo['city_need_all'] || 0;
    this.enumField_pic_full_url.fval = this.vo['pic_full_url'] || 0;
    this.enumField_is_field_type_ctl.fval = this.vo['is_field_type_ctl'] || 0;
    this.enumField_enum_type.fval = this.vo['enum_type'] || 0;
  }
}
</script>
<style rel="stylesheet/less" scoped lang="less">@import "../../common/style/mixin";
@dir: "edit/";
form {
    .submitBtn();
}
</style>
